<template>
  <div class="headerCart">
    <a href="#" @click.prevent="handleCart"
      ><span>购物车 {{ cartItemsCount }}</span></a
    >
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useCartStore } from '@/stores'
import router from '@/router'
const store = useCartStore()
// 获取store中购物车数量
const cartItemsCount = computed(() => {
  return store.itemsCount
})
// 跳转到购物车页面
const handleCart = () => {
  router.push('/cart')
}
</script>

<style scoped lang="less">
.headerCart {
  display: inline-block;
  position: relative;
  text-align: center;
  width: 100px;
  height: 30px;
  margin-top: 15px;
  margin-bottom: 20px;
  cursor: pointer;
  margin-left: 20px;
  background-color: red;
  vertical-align: middle;
  a {
    text-decoration: none;
    color: white;
    span {
      position: absolute;
      left: 2px;
      right: 2px;
      bottom: 5px;
    }
  }
}
</style>
